package com.xp.code.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.xp.code.util.SessionConfirmation;
import com.xp.code.view.XPInfoAction;

public class XPLoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 5717329386894161729L;

	public XPLoginInterceptor() {

	}

	@Override
	public String intercept(ActionInvocation invoke) throws Exception {
		String userID = SessionConfirmation.getUserID();
		if (userID == null || userID.length() == 0) {
			throw new Exception("无效用户，请先登录！");
		}
		try {
			Object action = invoke.getAction();
			if (action instanceof XPInfoAction) {
				XPInfoAction xpinfo = (XPInfoAction) action;
				xpinfo.setUserID(SessionConfirmation.getUserID());
				xpinfo.setUserName(SessionConfirmation.getUserName());
				xpinfo.setDeptID(SessionConfirmation.getDeptID());
				xpinfo.setDeptName(SessionConfirmation.getDeptName());
				xpinfo.setUnitID(SessionConfirmation.getUnitID());
				xpinfo.setUnitName(SessionConfirmation.getUnitName());
			}
		} catch (Exception e) {

		}
		return invoke.invoke();
	}

}
